package org.jeecg.modules.sistersophie.view;

import com.lowagie.text.DocumentException;
import org.jeecg.modules.sistersophie.util.FileUtil;
import org.jeecg.modules.sistersophie.util.VelocityUtil;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class InvoicePdfView extends AbstractPdfView {


    @Override
    protected void renderMergedOutputModel(Map<String, Object> map, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        VelocityUtil velocityUtil = new VelocityUtil();
        String templetPath = "/templates/1v1.vm";
        Map<String,Object> contractParam = new HashMap<>();
        ServletOutputStream os = httpServletResponse.getOutputStream();
        String invoiceContent = velocityUtil.convertTemplet(templetPath,map);
        FileUtil fileUtil = new FileUtil();
        try {
            fileUtil.createPDF(invoiceContent,os);
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                os.flush();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
